Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/model/src/commonMain/kotlin/org/meshtastic/core/model/util/CodePointUtils.kt 01cd54907d62cd90913d3d071b6bc240cae365ef (01cd5490) Text, 3.02 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.model.util

T8b949e/** Round Pushpin (📍) — the default waypoint icon, and the fallback for an unusable code point. */
Tff7b72const Tff7b72val Te6edf3PUSHPIN_CODE_POINT Tff7b72= T79c0ff0Te6edf3x1F4CD

Tff7b72private Tff7b72const Tff7b72val Te6edf3MAX_CODE_POINT Tff7b72= T79c0ff0Te6edf3x10FFFF
Tff7b72private Tff7b72const Tff7b72val Te6edf3MIN_SUPPLEMENTARY_CODE_POINT Tff7b72= T79c0ff0Te6edf3x10000
Tff7b72private Tff7b72const Tff7b72val Te6edf3MIN_HIGH_SURROGATE Tff7b72= T79c0ff0Te6edf3xD800
Tff7b72private Tff7b72const Tff7b72val Te6edf3MIN_LOW_SURROGATE Tff7b72= T79c0ff0Te6edf3xDC00
Tff7b72private Tff7b72const Tff7b72val Te6edf3MAX_LOW_SURROGATE Tff7b72= T79c0ff0Te6edf3xDFFF
Tff7b72private Tff7b72const Tff7b72val Te6edf3SURROGATE_SHIFT Tff7b72= T79c0ff1T79c0ff0
Tff7b72private Tff7b72const Tff7b72val Te6edf3LOW_SURROGATE_MASK Tff7b72= T79c0ff0Te6edf3x3FF

T8b949e/**
* Whether this is a Unicode scalar value: within the code point range and not an unpaired surrogate.
*
* `Character.isValidCodePoint` is JVM-only and additionally accepts lone surrogates, so this does the range check
* explicitly for `commonMain` callers.
*/
Tff7b72fun Te6edf3IntTb4b4b4.Td2a8ffisValidCodePointTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Tff7b72this Tff7b72in T79c0ff0.Tb4b4b4.Te6edf3MAX_CODE_POINT Tff7b72&Tff7b72& Tff7b72this Tff7b72!in Te6edf3MIN_HIGH_SURROGATETb4b4b4.Tb4b4b4.Te6edf3MAX_LOW_SURROGATE

T8b949e/**
* The icon to render for a waypoint, where `0` on the wire means "unset" and selects [PUSHPIN_CODE_POINT].
*
* Zero is a *valid* code point, so [toCodePointString] renders it as U+0000 rather than falling back. That matters
* because the trust-boundary clamp in `MeshDataHandlerImpl` normalises an unrenderable icon to `0` — every display and
* send path therefore has to read zero as the default rather than as a control character.
*/
Tff7b72fun Te6edf3IntTb4b4b4.Td2a8ffwaypointIconOrDefaultTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Int Tff7b72= Tff7b72if Tb4b4b4(Tff7b72this Tff7b72=Tff7b72= T79c0ff0Tb4b4b4) Te6edf3PUSHPIN_CODE_POINT Tff7b72else Tff7b72this

T8b949e/**
* Renders this Unicode code point as a string, substituting [fallback] when the value is not a usable scalar value.
*
* Code points that reach the UI may come from untrusted input, so they must not be handed to `Character.toChars`, which
* throws `IllegalArgumentException` on anything out of range.
*/
Tff7b72fun Te6edf3IntTb4b4b4.Td2a8fftoCodePointStringTb4b4b4(Te6edf3fallbackTb4b4b4: Tffa657Int Tff7b72= Te6edf3PUSHPIN_CODE_POINTTb4b4b4)Tb4b4b4: Tffa657String Tb4b4b4{
Tff7b72val Te6edf3codePoint Tff7b72=
Tff7b72when Tb4b4b4{
Te6edf3isValidCodePointTb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tff7b72this
Te6edf3fallbackTb4b4b4.Te6edf3isValidCodePointTb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3fallback
Tff7b72else Tff7b72-Tff7b72> Te6edf3PUSHPIN_CODE_POINT
Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3codePoint Tff7b72< Te6edf3MIN_SUPPLEMENTARY_CODE_POINTTb4b4b4) Tff7b72return Te6edf3codePointTb4b4b4.Te6edf3toCharTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3toStringTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3offset Tff7b72= Te6edf3codePoint Tff7b72- Te6edf3MIN_SUPPLEMENTARY_CODE_POINT
Tff7b72return Te6edf3charArrayOfTb4b4b4(
Tb4b4b4(Te6edf3MIN_HIGH_SURROGATE Tff7b72+ Tb4b4b4(Te6edf3offset Te6edf3ushr Te6edf3SURROGATE_SHIFTTb4b4b4)Tb4b4b4)Tb4b4b4.Te6edf3toCharTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4(Te6edf3MIN_LOW_SURROGATE Tff7b72+ Tb4b4b4(Te6edf3offset Te6edf3and Te6edf3LOW_SURROGATE_MASKTb4b4b4)Tb4b4b4)Tb4b4b4.Te6edf3toCharTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4.Te6edf3concatToStringTb4b4b4(Tb4b4b4)
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s